using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerPrimaryAttackState : PlayerState
{
    public int comboCounter;
    private float comboWindow = 2;
    private float lastAttackTime;

    public PlayerPrimaryAttackState(Player player, PlayerStateMachine playerStateMachine, string animBoolName) : base(player, playerStateMachine, animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        xInput = 0;
        if (comboCounter > 2 || Time.time > comboWindow + lastAttackTime)
            comboCounter = 0;
        player.animator.SetInteger("ComboCounter", comboCounter);
        float attackDir = player.faceDir;
        if (xInput != 0) attackDir = xInput;
        player.SetVelocity(player.attactMovement[comboCounter].x * attackDir, (player.attactMovement[comboCounter].y));
        stateTime = player.attackTime;
    }

    public override void Exit()
    {
        base.Exit();
        comboCounter++;
        lastAttackTime = Time.time;
        player.StartCoroutine("IsBusy", .1f);

    }

    public override void Update()
    {
        base.Update();
        if (stateTime > 0)
            player.SetZeroVelocity();
       
        if (triggerCalled)
            playerStateMachine.ChangeState(player.playerIdleState);
    }
}
